import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_page/mine_business/welfare/mine_income_page.dart';
import 'package:xvideos/hj_page/mine_business/welfare/welfare_view_task.dart';
import 'package:xvideos/tools_base/widget/keep_alive_widget.dart';

import '../../../tools_base/indicator/custom_tab_indicator.dart';
import 'lou_feng_ad_page.dart';

class WelfareHomePage extends StatefulWidget {
  WelfareHomePage({super.key});
  @override
  State<StatefulWidget> createState() {
    return _WelfareHomePageState();
  }
}

class _WelfareHomePageState extends State<WelfareHomePage> with TickerProviderStateMixin {
  final tabs = <String>['代理赚钱', "福利任务", "应用推荐"];
  late final TabController _tabController = TabController(initialIndex: index, length: tabs.length, vsync: this);
  late int index;
  @override
  void initState() {
    super.initState();
    index = Get.arguments ?? 0;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(titleSpacing: 0, centerTitle: true, title: Text('免费福利')),
      appBar: AppBar(
        automaticallyImplyLeading: false, // 不自动显示返回按钮
        toolbarHeight: 56, // 高度保持默认
        titleSpacing: 0, // 去除左右空隙
        title: Row(
          children: [
            // 返回按钮
            IconButton(
              icon: Icon(Icons.arrow_back_ios),
              onPressed: () => Navigator.pop(context),
            ),
            Expanded(
              child: TabBar(
                padding: EdgeInsets.symmetric(horizontal: 0, vertical: 5),
                isScrollable: false,
                tabAlignment: TabAlignment.center,
                labelStyle: TextStyle(fontSize: 14, color: Color(0xE5FFFFFF), fontWeight: FontWeight.w400),
                unselectedLabelStyle: TextStyle(fontSize: 14, color: Color(0x73FFFFFF)),
                indicator: CustomIndicator(
                    width: 18,
                    height: 4,
                    useGradient: true,
                    bottomLeft: 0,
                    bottomRight: 2,
                    topRight: 2,
                    topLeft: 2,
                    gradientColors: const [Color(0x55E1351F), Color(0xffE1351F)],
                    offsetY: -8),
                controller: _tabController,
                tabs: tabs.map((it) => Text(it)).toList(),
                labelPadding: EdgeInsets.symmetric(horizontal: 14, vertical: 2),
              ),
            ),
            SizedBox(width: 54),
          ],
        ),
      ),
      body: Column(
        children: [
          Expanded(
            child: TabBarView(
              controller: _tabController,
              children: [
                MineIncomePage().keepAlive,
                WelfareViewTask().keepAlive,
                LouFengAdPage().keepAlive,
              ],
            ),
          ),
        ],
      ),
    );
  }
}
